from rest_framework import serializers


class BaseListRetrieveSerializer(serializers.ModelSerializer):
    """
        基础的序列化器read方法， 只是提供了几个字段的格式化
    """
    created_by = serializers.StringRelatedField()
    created_at = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)
    modified_by = serializers.StringRelatedField()
    modified_at = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)

    class Meta:
        abstract = True


class BaseCreateSerializer(serializers.ModelSerializer):
    """
        基础的序列化器创建方法， 只是提供了created_by字段的自动记录
    """
    created_by = serializers.HiddenField(default=serializers.CurrentUserDefault())

    class Meta:
        abstract = True


class BaseUpdateSerializer(serializers.ModelSerializer):
    """
            基础的序列化器修改方法， 只是提供了modified_by字段的自动记录
    """
    modified_by = serializers.HiddenField(default=serializers.CurrentUserDefault())

    class Meta:
        abstract = True
